package shop.up.product.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import shop.up.common.result.Result;
import shop.up.model.product.*;
import shop.up.product.service.ManageService;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author zzc
 * @date 2023/3/28 16:18
 */
@Api(tags = "商品基础属性接口")
@RestController
@RequestMapping("/admin/product")
public class BaseManageController {

    @Resource
    private ManageService manageService;

    /**
     * 查询所有一级分类信息
     *
     * @return
     */
    @ApiOperation("查询所有一级分类信息")
    @GetMapping("getCategory1")
    public Result<List<BaseCategory1>> getCategory1() {
        List<BaseCategory1> baseCategory1List = manageService.getCategory1();
        return Result.ok(baseCategory1List);
    }

    /**
     * 根据一级categoryId查询所有二级分类
     *
     * @param category1Id
     * @return
     */
    @ApiOperation("根据一级categoryId查询所有二级分类")
    @GetMapping("getCategory2/{category1Id}")
    public Result<List<BaseCategory2>> getCategory2(@PathVariable("category1Id") Long category1Id) {
        List<BaseCategory2> category2List = manageService.getCategory2(category1Id);
        return Result.ok(category2List);
    }

    /**
     * 根据二级categoryId查询所有三级分类
     *
     * @param category2Id
     * @return
     */
    @ApiOperation("根据二级categoryId查询所有三级分类")
    @GetMapping("getCategory3/{category2Id}")
    public Result<List<BaseCategory3>> getCategory3(@PathVariable("category2Id") Long category2Id) {
        List<BaseCategory3> category3List = manageService.getCategory3(category2Id);
        return Result.ok(category3List);
    }

    /**
     * 根据分类Id 获取平台属性数据
     *
     * @param category1Id
     * @param category2Id
     * @param category3Id
     * @return
     */
    @ApiOperation("根据分类Id 获取平台属性数据")
    @GetMapping("attrInfoList/{category1Id}/{category2Id}/{category3Id}")
    public Result<List<BaseAttrInfo>> getBaseAttrInfoList(@PathVariable("category1Id") Long category1Id,
                                                          @PathVariable("category2Id") Long category2Id,
                                                          @PathVariable("category3Id") Long category3Id) {
        List<BaseAttrInfo> attrInfoList = manageService.getAttrInfoList(category1Id, category2Id, category3Id);
        return Result.ok(attrInfoList);
    }

    @ApiOperation("保存平台属性方法")
    @PostMapping("saveAttrInfo")
    public Result saveAttrInfo(@RequestBody BaseAttrInfo baseAttrInfo) {
        manageService.saveAttrInfo(baseAttrInfo);
        return Result.ok();
    }

    @ApiOperation("根据属性id获取属性值")
    @GetMapping("getAttrValueList/{attrId}")
    public Result<List<BaseAttrValue>> getAttrValueList(@PathVariable("attrId") Long attrId) {
        BaseAttrInfo attrInfo = manageService.getAttrInfo(attrId);
        List<BaseAttrValue> attrValueList = attrInfo.getAttrValueList();
        return Result.ok(attrValueList);
    }


}
